package com.huabo.system.service.impl;

import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.PageInfo;
import com.huabo.system.config.DateBaseConfig;
import com.huabo.system.mysql.mapper.TblAcctBookMySqlDao;
import com.huabo.system.oracle.entity.TblAcctBook;
import com.huabo.system.oracle.mapper.TblAcctBookDao;
import com.huabo.system.service.TblAcctBookService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblAcctBookServiceImpl implements TblAcctBookService {

    @Resource
    private TblAcctBookDao tblAcctBookDao;

    @Resource
    private TblAcctBookMySqlDao tblAcctBookMySqlDao;

    @Override
    public Map<String, Object> findByTypeNewZB(String token, Integer pageNumber, Integer pageSize, BigDecimal pid) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        try {
            if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
                PageInfo<TblAcctBook> pageInfo = new PageInfo<TblAcctBook>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                BigDecimal orgid = staff.getCurrentOrg().getOrgid();
                if (pid == null) {
                    pageInfo.setTlist(tblAcctBookDao.findByTypeNewZB(pageInfo, orgid));
                    pageInfo.setTotalRecord(tblAcctBookDao.selectCountt(orgid));
                } else {
                    pageInfo.setTlist(tblAcctBookDao.findByTypeNewZB(pageInfo, pid));
                    pageInfo.setTotalRecord(tblAcctBookDao.selectCountt(pid));
                }
                resultMap.put("pageInfo", pageInfo);
            } else {
                PageInfo<com.huabo.system.mysql.entity.TblAcctBookMySql> pageInfo = new PageInfo<com.huabo.system.mysql.entity.TblAcctBookMySql>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                BigDecimal orgid = staff.getCurrentOrg().getOrgid();
                if (pid == null) {
                    pageInfo.setTlist(tblAcctBookMySqlDao.findByTypeNewZB(pageInfo, orgid));
                    pageInfo.setTotalRecord(tblAcctBookMySqlDao.selectCountt(orgid));
                } else {
                    pageInfo.setTlist(tblAcctBookMySqlDao.findByTypeNewZB(pageInfo, pid));
                    pageInfo.setTotalRecord(tblAcctBookMySqlDao.selectCountt(pid));
                }
                resultMap.put("pageInfo", pageInfo);
            }


            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");

        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultMap;
    }


}
